<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>rgb转16进制的色值</title>
<script language="javascript">
<!--
function showRGB(obj){
    red=obj.red.value;
    green=obj.green.value
    blue=obj.blue.value;
    //将RGB转换16进制
     hexcode="#"+toHex(red)+toHex(green)+toHex(blue);
 document.bgColor=obj.hexval.value=hexcode;
}
function toHex(d){
    if(isNaN(d)){
     d=0;
 }
 //16进制转换方法
 var n=new Number(d).toString(16);
 return (n.length==1?"0"+n:n);
}//-->
</script>
<style>
.warp{ width:500px;margin: 0 auto;  }
ul li { list-style:none; height:30px;}
.warp span { width: 50px; display: block; float: left}
</style>
</head>
<body>
<div class="warp">
		<form name="rgbform">
        <br/> <br/> <br/> <br/>
			<ul>
            <h3>直接输入RGB是我值点击转换就可以</h3>
            <li> <b>请输入RGB颜色(0 to 255)</b></li>
            <li> <span> Red:</span>  <input type="text" name="red" size="5">  </li>
            <li><span>Green:</span> <input type="text" name="green" size="5"></li>
            <li><span>Blue:</span>  <input type="text" name="blue" size="5"></li>
            <li><input type="button" value="显示Hex #" onClick="showRGB(this.form)"></li>
            <li>Hex值为:  <input type="text" name="hexval" size="7"></li>

            </ul>

           <br>
			<br>
			<br>



		</form>
</div>
</body>
</html>
